import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver, ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { VantResolver } from '@vant/auto-import-resolver';

const timeStamp = new Date()
  .toISOString()
  .replace(/[-:T.]/g, '')
  .slice(2, 10); // 直接取 "YYMMDDHH"

// https://vitejs.dev/config/
export default defineConfig({
  build: {
    assetsInlineLimit: 10000,
    rollupOptions: {
      output: {
        assetFileNames: (assetInfo) => {  
          return `assets/${timeStamp}-[hash][extname]`;  
        }, 
        entryFileNames: (chunkInfo) => {
          return `run/${timeStamp}-[hash].js`;  
        },
        chunkFileNames: (chunkInfo) => {
          return `run/${timeStamp}-[hash].js`;  
        }
        
      }
    }
  },
  server: {
    // Vite 服务器选项
    port: 80, // 服务器端口
    host: '0.0.0.0', // 服务器绑定的 IP 地址
    // ...其他服务器选项
  },
  // ...其他配置项
  plugins: [
    vue(),
    AutoImport({
      imports: [
        'vue',
        {
          'naive-ui': [
            'useDialog',
            'useMessage',
            'useLoadingBar',
            'NTabs'
          ]
        }
      ],
      resolvers: [VantResolver(),ElementPlusResolver()]

    }),
    Components({
      resolvers: [NaiveUiResolver(), VantResolver(), ElementPlusResolver(),]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
